<template>
  <el-dialog
    :title="!dataForm.id ? '提现' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="银行卡号" prop="bankcardIdcard">
      <el-select v-model="dataForm.bankcardIdcard" placeholder="选择银行卡">
        <el-option v-for="bindCard in bindCards" :value="bindCard.bankcardIdcard" :key="bindCard.bankcardIdcard"             
               :label="bindCard.bankcardIdcard+bindCard.bankcardBankname"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="银行卡密码" prop="bankcardPassword">
      <el-input v-model="dataForm.bankcardPassword" type="password" placeholder="银行卡密码"></el-input>
    </el-form-item>
    <el-form-item label="提现金额" prop="accountflowMoney">
      <el-input v-model="dataForm.accountflowMoney" placeholder="提现金额(元)"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        bindCards:[],
        dataForm: {
          bankcardIdcard: '',
          bankcardPassword: '',
          accountflowMoney:'',
        },
        dataRule: {
          bankcardIdcard: [
            { required: true, message: '银行卡号不能为空', trigger: 'blur' }
          ],
          bankcardPassword: [
            { required: true, message: '银行卡密码不能为空', trigger: 'blur' }
          ],
          accountflowMoney: [
            { required: true, message: '充值金额不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.accountflowId = id || 0
        this.visible = true
        this.$http({
              url: this.$http.adornUrl(`/efinance/bankcard/list-bind`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {                                        
                this.bindCards=data.page.list
              }
        })
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.accountflowId) {
            this.$http({
              url: this.$http.adornUrl(`/expect/accountflow/info/${this.dataForm.accountflowId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.accountflowTime = data.accountflow.accountflowTime
                this.dataForm.accountflowType = data.accountflow.accountflowType
                this.dataForm.accountflowMoney = data.accountflow.accountflowMoney
                this.dataForm.accountflowPayeeaccount = data.accountflow.accountflowPayeeaccount
                this.dataForm.accountflowPayeename = data.accountflow.accountflowPayeename
                this.dataForm.accountflowPayeraccount = data.accountflow.accountflowPayeraccount
                this.dataForm.accountflowPayername = data.accountflow.accountflowPayername
                this.dataForm.accountflowBalance = data.accountflow.accountflowBalance
                this.dataForm.accountflowRemarks = data.accountflow.accountflowRemarks
                this.dataForm.accountflowStatus = data.accountflow.accountflowStatus
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/efinance/account/${!this.dataForm.accountflowId ? 'withdraw' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'bankcardIdcard': this.dataForm.bankcardIdcard,
                'bankcardPassword': this.dataForm.bankcardPassword,
                'accountflowMoney': this.dataForm.accountflowMoney
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
